<?
class Header extends Root{
	var $Content;
	var $Url;
	var $Tab;
	var $LastTab;
	var $Title;
	var $Body;
	var $Type;
	var $Description;
	var $Keywords;

	function Header ($Type="") {
		$proto = ($_SERVER["SSL_SESSION_ID"]!="")?"https":"http";
		$this->Url=$proto.'://'.$GLOBALS["HTTP_SERVER_VARS"]["HTTP_HOST"].'/';
		$this->Title = $GLOBALS["Systeme"]->Titre;
		$this->Description = $GLOBALS["Systeme"]->Description;
		$this->Keywords = $GLOBALS["Systeme"]->MotsCles;
		$this->Type = $Type;
		$this->Body="";
	}

	function setTitle($Temp) {
		$this->Title = $Temp;
	}
	function setBody($Temp) {
		$this->Body = $Temp;
	}
	function setDescription($Temp) {
		$this->Description = $Temp;
	}
	function setClassification($Temp) {
		$this->Classification = $Temp;
	}
	function setReplyTo($Temp) {
		$this->ReplyTo = $Temp;
	}
	function setKeywords($Temp) {
		$this->Keywords = $Temp;
	}
	function setFrameset($Tab,$Data="",$Name=0) {
		//Analyse du tableau et construction de la chaine
		if (is_array($Tab)) {
			$Data.="<frameset ";
			//Recuperation des attributs
			if (is_array($Tab["@"]))foreach ($Tab["@"] as $Key=>$Value) $Data.=$Key."=\"".$Value."\" ";
			$Data.=">";
			//Recuperation des frames
			if (is_array($Tab["#"]["FRAME"]))foreach ($Tab["#"]["FRAME"] as $Value) $Data.=$this->setFrame($Value);
			//Recuperation des frameset
			if (is_array($Tab["#"]["FRAMESET"]))foreach ($Tab["#"]["FRAMESET"] as $Value) $Data.=$this->setFrameset($Value);
			//Recuperation des noframes
			if (is_array($Tab["#"]["NOFRAME"]))foreach ($Tab["#"]["NOFRAME"] as $Value) $Data.=$this->setNoFrame($Value);
			$Data.="</frameset>";
			$this->Frameset[$Name] = $Data;
			return $Data;
		}
	}
	function setFrame($Tab) {
		//Analyse du tableau et construction de la chaine
		//Analyse du tableau et construction de la chaine
		$Data.="<frame ";
		//Recuperation des attributs
		if (is_array($Tab["@"]))foreach ($Tab["@"] as $Key=>$Value) {
			if ($Key=="name") $Name = $Value;
			if ($Key=="src") {
				$Value = str_replace("[URL]",$GLOBALS["Systeme"]->RegVars["Lien"],$Value);
				$Data.=$Key."=\"".$Value."\" ";
			}else{
				$Data.=$Key."=\"".$Value."\" ";
			}
		}
		//Recuperation des frameset
		if (is_array($Tab["#"]["FRAMESET"]))foreach ($Tab["#"]["FRAMESET"] as $Value) $this->setFrameset($Value,"",$Name);

		$Data.=" />";
		return $Data;
	}

	function setNoFrame($Tab) {
		//Analyse du tableau et construction de la chaine
		//Analyse du tableau et construction de la chaine
		$Data.="<noframe ";
		//Recuperation des attributs
		if (is_array($Tab["@"]))foreach ($Tab["@"] as $Key=>$Value) $Data.=$Key."=\"".$Value."\" ";
		$Data.=" >";
		$Data.="</noframe>";
		return $Data;
	}

	function isNotInTab($Data) {
		if (count($this->Tab)>0) {
			foreach ($this->Tab as $Key) {
				if ($Key==$Data) return false;
			}
		}
		return true;
	}

	function isNotInLastTab($Data) {
		if (count($this->LastTab)>0) {
			foreach ($this->LastTab as $Key) {
				if ($Key==$Data) return false;
			}
		}
		return true;
	}

	function Add($Data,$Vars) {
		if ($Vars!="Last"){
			if ($this->isNotInTab($Data)) $this->Tab[] = $Data;
		}else{
			if ($this->isNotInLastTab($Data)) $this->LastTab[] = $Data;
		}
	}

	function getTab() {
		if (count($this->Tab)>0) {
			foreach ($this->Tab as $Key) {
				$Result.="$Key\r\n";
			}
		}
		return $Result;
	}

	function getLastTab() {
		if (count($this->LastTab)>0) {
			foreach ($this->LastTab as $Key) {
				$Result.="$Key\r\n";
			}
		}
		return $Result;
	}

	function getFrame() {
		//Construction de la structure de frame
			$Result="<script>";
			$Result.="
				if (parent.frames.length<2){
					//Le cas ou c est la premiere page donc ecriture des frames
					document.write('".$this->Frameset[0]."');
				}";
			if (sizeof($this->Frameset)>1){
				$Result.="else{";
				$i=0;
				foreach ($this->Frameset as $Key=>$Value) {
					if ($Key!="0") {
						$Result.="
							if (this.name=='".$Key."'){	
								document.write('".$Value."');
							}
							";
					}
					$i++;
				}
				$Result.="}";
			}
			$Result.='</script>
			<body '.$this->Body.'>'; 
			return $Result;
		
	}

	function Affich() {

		$this->Content ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
       				"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
			<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
			<title>'.$this->Title.'</title>
			<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET_CODE.'" />
			<meta name="description" content="'.$this->Description.'"/>
			<meta name="keywords" content="'.$this->Keywords.'"/>
			<meta name="revisit-after" content="15 days"/>
			<meta name="URL" content="'.$GLOBALS["Systeme"]->Url.'"/>
			<meta name="author" content=" Expressiv Internet Technologies - Montpellier , France "/>
			<meta name="reply-to" content="'.$GLOBALS["Systeme"]->ReplyTo.'"/>
			<meta name="Classification" content="'.$GLOBALS["Systeme"]->Classification.'"/>
			<meta http-equiv="Content-Language" content="fr,en"/>
			<meta name="robots" content="index,follow"/>
			<meta name="copyright" content="Expressiv"/>
			<meta name="rating" content="general"/>
			';
		if ($this->Type==""){
			$this->Content .= '<link title="test" type="text/css" rel="stylesheet" href="'.$this->Url.'Skins/'.$GLOBALS["Systeme"]->User->Skin.'/Css/style.css" />';
		}else{
			$this->Content .= '<link title="test" type="text/css" rel="stylesheet" href="'.$this->Url.'Skins/'.$GLOBALS["Systeme"]->User->Skin.'/Css/print.css" />';
		}
		$this->Content .= $this->getTab();
		$this->Content .= $this->getLastTab();
		$this->Content .='

			</head>
			';
		if ($this->Frameset!="") {
			//il y a donc une frame
			$this->Content .= $this->getFrame();
		}else{ 
			$this->Content.='<body '.$this->Body.'>';
		}

				
		return $this->Content;
	}

	function getFooter(){
		
		return '</body></html>';
	}
}


?>
